import React, { useCallback } from "react"
import { Field_FormSave, Field_name_id } from "@/components/utils/field.list"
import { FormProps } from "@/components/modal/form.modal"
import { FormRender } from "@whzhuke/antd"
import useForm from "antd/es/form/hooks/useForm"
import companiesService from "@/services/companies.service"

interface Props {
  values?: any
}
export const EditCompanies: React.FC<Props & FormProps> = props => {
  const { values, onDone } = props
  const [form] = useForm<any>()
  const onFinish = useCallback(data => {
    companiesService[values ? "edit" : "save"]({ ...data }).then(res => {
      onDone?.()
    })
  }, [])

  return (
    <FormRender
      form={form}
      initialValues={
        values
          ? {
              ...values
            }
          : {}
      }
      layout="horizontal"
      preserve={false}
      onFinish={onFinish}
      labelCol={{ span: 8 }}
      wrapperCol={{ span: 16 }}
      style={{ width: 600 }}
      fieldList={[
        values ? Field_name_id : undefined,
        {
          fieldType: "input",
          formItemConfig: { required: !0, name: "name", label: "供应商名称" },
          config: { placeholder: "供应商名称" }
        },
        {
          fieldType: "input",
          formItemConfig: { required: !0, name: "address", label: "地址" },
          config: { placeholder: "地址" }
        },
        {
          fieldType: "input",
          formItemConfig: { required: !0, name: "contacts", label: "联系人" },
          config: { placeholder: "联系人" }
        },
        {
          fieldType: "input",
          formItemConfig: { required: !0, name: "username", label: "账号" },
          config: { placeholder: "账号" }
        },
        {
          fieldType: "input",
          formItemConfig: { required: !0, name: "belongBank", label: "开户行" },
          config: { placeholder: "开户行" }
        },

        {
          fieldType: "select",
          formItemConfig: {
            required: !0,
            name: "type",
            label: "公司性质"
          },
          config: {
            placeholder: "请选择公司性质",
            options: [
              {
                label: "供应商",
                value: 1
              },
              {
                label: "国外客户",
                value: 2
              }
            ]
          }
        },

        {
          fieldType: "input",
          formItemConfig: { required: !0, name: "account", label: "银行账号" },
          config: { placeholder: "银行账号" }
        },
        {
          fieldType: "input",
          formItemConfig: { required: !0, name: "taxpayerCode", label: "税号" },
          config: { placeholder: "税号" }
        },

        { ...Field_FormSave, formItemConfig: { wrapperCol: { offset: 8, span: 16 } } }
      ]}
      autoComplete="off"
    />
  )
}
